{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Question 54\n",
    "\n",
    "### **Question**\n",
    "\n",
    "> **_Assuming that we have some email addresses in the \"username@companyname.com\" format, please write program to print the company name of a given email address. Both user names and company names are composed of letters only._**\n",
    "\n",
    "> **_Example:\n",
    "> If the following email address is given as input to the program:_**\n",
    "\n",
    "\n",
    "> john@google.com\n",
    "\n",
    "\n",
    "> **_Then, the output of the program should be:_**\n",
    "\n",
    "\n",
    "> google\n",
    "\n",
    "\n",
    "> **_In case of input data being supplied to the question, it should be assumed to be a console input._**\n",
    "\n",
    "---\n",
    "\n",
    "### Hints\n",
    "\n",
    "> **_Use \\w to match letters._**\n",
    "\n",
    "---\n",
    "\n",
    "\n",
    "\n",
    "**Solutions:**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import re\n",
    "\n",
    "email = \"john@google.com elise@python.com\"\n",
    "pattern = \"\\w+@(\\w+).com\"\n",
    "ans = re.findall(pattern, email)\n",
    "print(ans)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---\n",
    "\n",
    "# Question 55\n",
    "\n",
    "### **Question**\n",
    "\n",
    "> **_Write a program which accepts a sequence of words separated by whitespace as input to print the words composed of digits only._**\n",
    "\n",
    "> **_Example:\n",
    "> If the following words is given as input to the program:_**\n",
    "\n",
    "\n",
    "> 2 cats and 3 dogs.\n",
    "\n",
    "\n",
    "> **_Then, the output of the program should be:_**\n",
    "\n",
    "\n",
    "> ['2', '3']\n",
    "\n",
    "\n",
    "> **_In case of input data being supplied to the question, it should be assumed to be a console input._**\n",
    "\n",
    "---\n",
    "\n",
    "### Hints\n",
    "\n",
    "> **_Use re.findall() to find all substring using regex._**\n",
    "\n",
    "---\n",
    "\n",
    "\n",
    "\n",
    "**Solutions:**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import re\n",
    "\n",
    "email = input()\n",
    "pattern = \"\\d+\"\n",
    "ans = re.findall(pattern, email)\n",
    "print(ans)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**OR**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "email = input().split()\n",
    "ans = []\n",
    "for word in email:\n",
    "    if word.isdigit():  # can also use isnumeric() / isdecimal() function instead\n",
    "        ans.append(word)\n",
    "print(ans)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**OR**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "email = input().split()\n",
    "ans = [word for word in email if word.isdigit()]  # using list comprehension method\n",
    "print(ans)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---\n",
    "\n",
    "# Question 56\n",
    "\n",
    "### **Question**\n",
    "\n",
    "> **_Print a unicode string \"hello world\"._**\n",
    "\n",
    "---\n",
    "\n",
    "### Hints\n",
    "\n",
    "> **_Use u'strings' format to define unicode string._**\n",
    "\n",
    "---\n",
    "\n",
    "\n",
    "\n",
    "# Question 57\n",
    "\n",
    "### **Question**\n",
    "\n",
    "> **_Write a program to read an ASCII string and to convert it to a unicode string encoded by utf-8._**\n",
    "\n",
    "---\n",
    "\n",
    "### Hints\n",
    "\n",
    "> **_Use unicode()/encode() function to convert._**\n",
    "\n",
    "---\n",
    "\n",
    "\n",
    "\n",
    "**Solutions:**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "s = input()\n",
    "u = s.encode(\"utf-8\")\n",
    "print(u)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---\n",
    "\n",
    "# Question 58\n",
    "\n",
    "### **Question**\n",
    "\n",
    "> **_Write a special comment to indicate a Python source code file is in unicode._**\n",
    "\n",
    "---\n",
    "\n",
    "### Hints\n",
    "\n",
    "> **_Use unicode() function to convert._**\n",
    "\n",
    "---\n",
    "\n",
    "**Solution:**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# -*- coding: utf-8 -*-"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---\n",
    "\n",
    "# Question 59\n",
    "\n",
    "### **Question**\n",
    "\n",
    "> **_Write a program to compute 1/2+2/3+3/4+...+n/n+1 with a given n input by console (n>0)._**\n",
    "\n",
    "> **_Example:\n",
    "> If the following n is given as input to the program:_**\n",
    "\n",
    "\n",
    "> 5\n",
    "\n",
    "\n",
    "> **_Then, the output of the program should be:_**\n",
    "\n",
    "\n",
    "> 3.55\n",
    "\n",
    "\n",
    "> **_In case of input data being supplied to the question, it should be assumed to be a console input._**\n",
    "\n",
    "---\n",
    "\n",
    "### Hints\n",
    "\n",
    "> **_Use float() to convert an integer to a float.Even if not converted it wont cause a problem because python by default understands the data type of a value_**\n",
    "\n",
    "---\n",
    "\n",
    "\n",
    "\n",
    "**Solutions:**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "n = int(input())\n",
    "sum = 0\n",
    "for i in range(1, n + 1):\n",
    "    sum += i / (i + 1)\n",
    "print(round(sum, 2))  # rounded to 2 decimal point"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
